package com.anxin.act.config.web;

import java.util.List;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.anxin.framework.aspectj.lang.annotation.Log;
import com.anxin.framework.aspectj.lang.enums.BusinessType;
import com.anxin.act.config.entity.WfApplyForm;
import com.anxin.act.config.service.WfApplyFormService;
import com.anxin.framework.web.controller.BaseController;
import com.anxin.framework.web.entity.AjaxResult;
import com.anxin.common.utils.poi.ExcelUtil;
import com.anxin.framework.web.page.TableDataInfo;

/**
 * 流程申请单Controller
 *
 * @author 刘翔宇
 * @date 2020-03-13
 */
@RestController
@RequestMapping("/form/wfApplyForm")
public class WfApplyFormController extends BaseController{
    @Autowired
    private WfApplyFormService wfApplyFormService;

    /**
     * 查询流程申请单列表
     */
    @PreAuthorize("@ss.hasPermi('act:config:view')")
    @GetMapping("/list")
    @Log(title = "查询流程申请单列表", businessType = BusinessType.LIST)
    public TableDataInfo list(WfApplyForm wfApplyForm){
        startPage();
        List<WfApplyForm> list = wfApplyFormService.findList(wfApplyForm);
        return getDataTable(list);
    }

    /**
     * 导出流程申请单列表
     */
    @PreAuthorize("@ss.hasPermi('act:config:export')")
    @Log(title = "流程申请单", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(WfApplyForm wfApplyForm) {
        List<WfApplyForm> list = wfApplyFormService.findList(wfApplyForm);
        ExcelUtil<WfApplyForm> util = new ExcelUtil<WfApplyForm>(WfApplyForm.class);
        return util.exportExcel(list, "form");
    }

    /**
     * 获取流程申请单详细信息
     */
    @PreAuthorize("@ss.hasPermi('act:config:view')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") String id){
        return AjaxResult.success(wfApplyFormService.getById(id));
    }

    /**
     * 保存流程申请单
     */
    @PreAuthorize("@ss.hasPermi('act:config:edit')")
    @Log(title = "流程申请单", businessType = BusinessType.INSERT)
    @PostMapping("/save")
    public AjaxResult save(@RequestBody WfApplyForm wfApplyForm){
        return toAjax(wfApplyFormService.save(wfApplyForm));
    }


    /**
     * 删除流程申请单
     */
    @PreAuthorize("@ss.hasPermi('act:config:remove')")
    @Log(title = "流程申请单", businessType = BusinessType.DELETE)
	@DeleteMapping("/{id}")
    public AjaxResult delete(@PathVariable(("id")) String id){
        return toAjax(wfApplyFormService.deleteById(id));
    }

    /**
     * 根据表单类型获取表单集合
     * @param formType 表单类型
     * @return
     */
    @GetMapping("/getFormList/{formType}")
    public AjaxResult getFormList(@PathVariable("formType") String formType){
        return wfApplyFormService.getFormList(formType);
    }

}
